package com.health.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.health.system.entity.HealthSuggestions;
import com.health.system.service.HealthSuggestionsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-06-22
 */
@Validated
@Api(tags = "健康建议管理")
@RestController
public class HealthSuggestionsController {

    @Autowired
    private HealthSuggestionsService healthSuggestionsService;

    @ApiOperation(value = "查看全部健康建议")
    @GetMapping("/admin/health/suggestions")
    public IPage<HealthSuggestions> getAllHealthSuggestions(@RequestParam(value = "current", defaultValue = "1") Long current,
                                                            @RequestParam(value = "size", defaultValue = "10") Long size) {
        return healthSuggestionsService.getAllHealthSuggestions(current, size);
    }

    @ApiOperation(value = "根据ID查询健康建议")
    @GetMapping("/admin/health/suggestions/{id}")
    public HealthSuggestions getHealthSuggestionsById(@PathVariable Integer id) {
        return healthSuggestionsService.getHealthSuggestionsById(id);
    }

    @ApiOperation(value = "根据星级查询健康建议")
    @GetMapping("/admin/health/suggestions/stars/{stars}")
    public List<HealthSuggestions> getHealthSuggestionsByStars(@PathVariable String stars) {
        return healthSuggestionsService.getHealthSuggestionsByStars(stars);
    }

    @ApiOperation(value = "新增健康建议")
    @PostMapping("/admin/health/suggestions")
    public void addHealthSuggestions(@RequestBody HealthSuggestions healthSuggestions) {
        healthSuggestionsService.addHealthSuggestions(healthSuggestions);
    }

    @ApiOperation(value = "修改健康建议")
    @PutMapping("/admin/health/suggestions")
    public void updateHealthSuggestions(@RequestBody HealthSuggestions healthSuggestions) {
        healthSuggestionsService.updateHealthSuggestions(healthSuggestions);
    }

    @ApiOperation(value = "删除健康建议")
    @DeleteMapping("/admin/health/suggestions/{id}")
    public void deleteHealthSuggestions(@PathVariable Integer id) {
        healthSuggestionsService.deleteHealthSuggestions(id);
    }
}
